package com.devilwwj.http.core;

import com.devilwwj.http.callback.OnProgressUpdatedListener;
import com.devilwwj.http.exception.HttpException;

import org.apache.http.HttpResponse;

import java.net.HttpURLConnection;

/**
 * 回调基础接口
 * Created by devilwwj on 15/7/16.
 */
public interface ICallback<T> {
    void onSuccess(T result);
    void onFailure(HttpException e);
    T handle(HttpResponse response, OnProgressUpdatedListener listener) throws HttpException;
    T handle(HttpResponse response) throws HttpException;
    T handle(HttpURLConnection connection, OnProgressUpdatedListener listener) throws HttpException;
    T handle(HttpURLConnection connection) throws HttpException;
    T bindData(String content) throws HttpException;

    void onProgressUpdate(int state, int curLen, int totalLen);

    void cancel();

    /**
     * invoked on sub thread
     * @param t serialized by SubCallbacks
     * @return final result by calling onSuccess(t)
     */
    T postRequest(T t);

    /**
     * invoked on sub thread
     * @return if not null, will skip the http request, call{@link #onSuccess(Object)} directly
     */
    T preRequest();

}
